package com.fhx.core.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.fhx.core.R
import kotlinx.android.synthetic.main.layout_virtual_keyboard.view.*
import java.util.*
import kotlin.collections.ArrayList

class VirtualKeyboardView(context: Context, attrs: AttributeSet?) : RelativeLayout(context, attrs) {


    private var valueList: ArrayList<Map<String, String>>? = null //有人可能有疑问，为何这里不用数组了？
    init {
        val view = View.inflate(context, R.layout.layout_virtual_keyboard, null)
        valueList = ArrayList()
        initValueList()
        //setupView()
        addView(view) //必须要，不然不显示控件

    }

    fun getLayoutBack(): RelativeLayout? {
        return layoutBack
    }

    fun getValueList(): ArrayList<Map<String, String>>? {
        return valueList
    }

    private fun initValueList() {
        // 初始化按钮上应该显示的数字
        for (i in 1..12) {
            val map: MutableMap<String, String> =
                HashMap()
            if (i < 10) {
                map["name"] = i.toString()
            } else if (i == 10) {
                map["name"] = "."
            } else if (i == 11) {
                map["name"] = 0.toString()
            } else if (i == 12) {
                map["name"] = ""
            }
            valueList?.add(map)
        }
    }

    fun getGridView(): RecyclerView? {
        return rv_keyBoard
    }

//    private fun setupView() {
//        val keyBoardAdapter = KeyBoardAdapter(context,valueList)
//        OtherTool.configRecyclerView(rv_keyBoard, GridLayoutManager(context!!,4))
//        rv_keyBoard.adapter=keyBoardAdapter
//    }
}